<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="assets/images/favicon.ico" rel="icon">
    <title>EasyWeb后台管理模板</title>
    <link rel="stylesheet" href="assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="layui-layout-body">
<!-- 表单弹窗 -->
<script type="text/html" id="resetpassword">
    <form id="userEditForm" lay-filter="userEditForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">原始密码</label>
            <div class="layui-input-block">
                <input type="password" name="oldpwd" placeholder="请输入原始密码" class="layui-input"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newpwd" placeholder="请输入新密码" class="layui-input"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="resetpassword" lay-submit>修改</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<div class="layui-layout layui-layout-admin">
    <!-- 头部 -->
    <div class="layui-header">
        <div class="layui-logo">
            <img src="assets/images/logo.png"/>
            <cite>&nbsp;EasyWeb iframe</cite>
        </div>
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="flexible" title="侧边伸缩"><i class="layui-icon layui-icon-shrink-right"></i></a>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="refresh" title="刷新"><i class="layui-icon layui-icon-refresh-3"></i></a>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="message" title="消息">
                    <i class="layui-icon layui-icon-notice"></i>
                    <span class="layui-badge-dot"></span>
                </a>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="note" title="便签"><i class="layui-icon layui-icon-note"></i></a>
            </li>
            <li class="layui-nav-item layui-hide-xs" lay-unselect>
                <a ew-event="fullScreen" title="全屏"><i class="layui-icon layui-icon-screen-full"></i></a>
            </li>
            <li class="layui-nav-item layui-hide-xs" lay-unselect>
                <a ew-event="lockScreen" title="锁屏"><i class="layui-icon layui-icon-password"></i></a>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a>
                    <img src="assets/images/head.jpg" class="layui-nav-img">
                    <cite>${user.nickName}</cite>
                </a>
                <dl class="layui-nav-child">
<%--                    <dd lay-unselect><a ew-href="page/template/user-info.html">个人中心</a></dd>--%>
                    <dd lay-unselect><a id="resetpwd">修改密码</a></dd>
                    <hr>
                    <dd lay-unselect><a id="logout" >退出</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="theme" title="主题"><i class="layui-icon layui-icon-more-vertical"></i></a>
            </li>
        </ul>
    </div>
    <!-- 侧边栏 -->
    <div class="layui-side">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree arrow2" lay-filter="admin-side-nav" lay-shrink="_all">
                <c:if test="${user.roleId==1}">
                    <li class="layui-nav-item">
                        <a><i class="layui-icon layui-icon-set"></i>&emsp;<cite>系统管理</cite></a>
                        <dl class="layui-nav-child">
                            <dd><a lay-href="${path}/view/user.jsp">用户管理</a></dd>
<%--                            <dd><a lay-href="${path}/view/role.jsp">角色管理</a></dd>--%>
                        </dl>
                    </li>
                </c:if>

                <li class="layui-nav-item">
                    <a><i class="layui-icon layui-icon-set"></i>&emsp;<cite>资源中心</cite></a>
                    <dl class="layui-nav-child">
                        <c:if test="${user.roleId==1}">
                            <dd><a lay-href="">上传文件</a></dd>
                        </c:if>
                        <dd><a lay-href="">下载文件</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>

    <!-- 主体部分 -->
    <div class="layui-body"></div>
    <!-- 底部 -->
    <div class="layui-footer layui-text">
        copyright © 2020 <a href="http://easyweb.vip" target="_blank">easyweb.vip</a> all rights reserved.
        <span class="pull-right">Version 3.1.8</span>
    </div>
</div>

<!-- 加载动画 -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="./assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="./assets/js/common.js?v=318"></script>
<script>
    layui.use(['index','admin','layer','form'], function () {
        var $ = layui.jquery;
        var index = layui.index;
        var admin = layui.admin;
        var layer = layui.layer;
        var form = layui.form;
        // 默认加载主页
        index.loadHome({
            menuPath: 'page/console/workplace.html',
            menuName: '<i class="layui-icon layui-icon-home"></i>'
        });

        $('#resetpwd').click(function () {
            admin.open({
                type: 1,
                title: '修改密码',
                content: $('#resetpassword').html(),
                success: function (layero, dIndex) {
                    //监听表单的提交
                    form.on('submit(resetpassword)', function (data) {
                         //获取新密码和旧密码 发送ajax请求
                        $.post('${path}/user?method=replacepwd',data.field,function (res) {

                              if(res.code==0){  // 请求退出登录
                                  $.post("${path}/user?method=logout",function (res) {
                                      if(res.code==0){
                                          layer.msg('修改密码成功',{icon:1},function () {
                                              window.location.href = "${path}/login.jsp"
                                          })
                                      }else{
                                          layer.msg(res.msg,{icon:2})
                                      }
                                  })
                              }else{
                                  layer.msg(res.msg,{icon:2})
                              }
                        },'JSON')

                        return false;
                    });
                }
            })
        })

        $("#logout").click(function () {
            layer.confirm('确定要退出吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                $.post("${path}/user?method=logout",function (res) {
                    if(res.code==0){
                        layer.msg(res.msg,{icon:1},function () {
                            window.location.href = "${path}/login.jsp"
                        })
                    }else{
                        layer.msg(res.msg,{icon:2})
                    }
                })
            });
        })
    });
</script>
</body>
</html>
